// pages/ui/mymember/mymember.js
var that;
var mapContext;
var locationArr;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scale: 16,//地图显示级别
    markers: [{
      iconPath: "../../../res/icon_vip.png",
      id: 0,
      latitude: 30.25961,
      longitude: 120.13026,
      width: 18,
      height: 20
    }],
    memberImg1:"../../../res/head1.jpeg",
    memberImg2: "../../../res/head2.jpeg",
    memberImg3: "../../../res/head3.jpeg",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;//初始化
    //获得地图
    locationArr = [];
    mapContext = wx.createMapContext('map');
    that.getCityLocation();
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  
  /**
   * 获取定位
   */
  getCityLocation: function () {
    wx.getLocation({
      type: 'wgs84', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
      success: function (res) {
        //console.log(res);
        var locationString = res.latitude + "," + res.longitude;
        for (var i = 0; i < 13; i++) {
          locationArr.push({
            iconPath: "../../../res/icon_vip.png",
            id: i,
            latitude: res.latitude - 0.01 * (Math.random() - Math.random()),
            longitude: res.longitude + 0.009 * (Math.random() - Math.random()),
            width: 18,
            height: 20
          })
        }
        console.log(locationArr+'----');
        that.setData({
          markers: locationArr,
          lat: res.latitude,
          lon: res.longitude
        })
      },
      fail: function () {
        // fail
        console.log("定位失败");
      },
      complete: function () {
        // complete
        console.log("定位完成");
      }
    })
  }

})